package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SjRadomStandard;
import com.ruoyi.system.domain.SjStandard;
import com.ruoyi.system.mapper.SjRadomStandardMapper;
import com.ruoyi.system.mapper.SjStandardMapper;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SjRandomRecordMapper;
import com.ruoyi.system.domain.SjRandomRecord;
import com.ruoyi.system.service.ISjRandomRecordService;

/**
 * 随机记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-04
 */
@Service
public class SjRandomRecordServiceImpl implements ISjRandomRecordService 
{
    @Autowired
    private SjRandomRecordMapper sjRandomRecordMapper;

    @Autowired
    private SjRadomStandardMapper sjRadomStandardMapper;

    @Autowired
    private SjStandardMapper sjStandardMapper;

    /**
     * 查询随机记录
     * 
     * @param id 随机记录主键
     * @return 随机记录
     */
    @Override
    public SjRandomRecord selectSjRandomRecordById(Long id)
    {
        return sjRandomRecordMapper.selectSjRandomRecordById(id);
    }

    /**
     * 查询随机记录列表
     * 
     * @param sjRandomRecord 随机记录
     * @return 随机记录
     */
    @Override
    public List<SjRandomRecord> selectSjRandomRecordList(SjRandomRecord sjRandomRecord)
    {
        return sjRandomRecordMapper.selectSjRandomRecordList(sjRandomRecord);
    }

    /**
     * 查询随机记录列表
     *
     * @param sjRandomRecord 随机记录
     * @return 随机记录
     */
    @Override
    public List<SjStandard> selectSjStandardList(SjRandomRecord sjRandomRecord)
    {
        SjRadomStandard sjRadomStandard = new SjRadomStandard();
        sjRadomStandard.setRecordId(sjRandomRecord.getId());
        //根据记录id获取 随机标准列表
        List<SjRadomStandard> list = sjRadomStandardMapper.selectSjRadomStandardList(sjRadomStandard);
        List<SjStandard> listStandard = new ArrayList<>();
        //循环随机标准列表 根据identify获取标准集合
        for(SjRadomStandard sjRadomStandard1 : list){
            SjStandard standard = sjStandardMapper.selectSjStandardListByIdentify(sjRadomStandard1.getStandIden());
            if(standard!=null){
                listStandard.add(standard);
            }
        }
        return listStandard;
    }




    /**
     * 新增随机记录
     * 
     * @param sjRandomRecord 随机记录
     * @return 结果
     */
    @Override
    public int insertSjRandomRecord(SjRandomRecord sjRandomRecord)
    {
        return sjRandomRecordMapper.insertSjRandomRecord(sjRandomRecord);
    }

    /**
     * 修改随机记录
     * 
     * @param sjRandomRecord 随机记录
     * @return 结果
     */
    @Override
    public int updateSjRandomRecord(SjRandomRecord sjRandomRecord)
    {
        return sjRandomRecordMapper.updateSjRandomRecord(sjRandomRecord);
    }

    /**
     * 批量删除随机记录
     * 
     * @param ids 需要删除的随机记录主键
     * @return 结果
     */
    @Override
    public int deleteSjRandomRecordByIds(Long[] ids)
    {
        return sjRandomRecordMapper.deleteSjRandomRecordByIds(ids);
    }

    /**
     * 删除随机记录信息
     * 
     * @param id 随机记录主键
     * @return 结果
     */
    @Override
    public int deleteSjRandomRecordById(Long id)
    {
        return sjRandomRecordMapper.deleteSjRandomRecordById(id);
    }

    /**
     * 数量统计
     *
     * @param
     * @return 结果
     */
    public String countStandardRecord(){
        return sjRandomRecordMapper.countStandardRecord();
    }
}
